// index.js
import Toast from '@vant/weapp/toast/toast';

Page({
  data: {
    form: {
      username: '201711010001',
      password: ''
    },
    a: '',
    b: ''
  },
  fn() {
    let v = true
    if (!this.data.form.username) {
      v = false
      this.setData({
        a: "用户名不能为空"
      })
    } else {
      this.setData({
        a: ""
      })
    }
    if (!this.data.form.password) {
      v = false
      this.setData({
        b: "密码不能为空"
      })
    } else {
      this.setData({
        b: ""
      })
    }
    return v
  },
  fn1(e) {
    console.log(e);
    this.setData({
      "form.username": e.detail
    })
  },
  fn2(e) {
    this.setData({
      "form.password": e.detail
    })
  },
  logging() {
    if (this.fn()) {
      wx.request({
        url: 'http://124.223.9.151:9009/api/user/login',
        method: 'POST',
        data: {
          username: this.data.form.username,
          password: this.data.form.password,
          userType: 1
        },
        success: (res => {
          console.log(res.data);
          if (res.data.code === 0) {
            Toast({
              type: 'success',
              message: '提交成功',
              onClose: () => {
                wx.setStorageSync('userInfo', res.data)
                wx.switchTab({
                  url: '/pages/class-look/class-look',
                })
              },
            });
          } else {
            Toast.fail('失败文案');
          }
        }),
      })
    }

  }



})